<template>
  <div>
    <el-tree :data="data"
             :props="defaultProps"
             :expand-on-click-node="false">
      <span class="custom-tree-node"
            slot-scope="{ node ,data}"
            @click="getNode(data)">
        <span>{{ node.label }}</span>
      </span>
    </el-tree>
  </div>
</template>

<script>
import PubSub from 'pubsub-js'
export default {
  components: {},
  data () {
    return {
      data: [],
      defaultProps: {
        children: 'categoryEntities',
        label: 'name'
      }
    }
  },
  created () {
    this.getTreeList()
  },
  methods: {
    getTreeList () {
      this.$http({
        url: this.$http.adornUrl('/product/category/treeList', false),
        method: 'get'
      }).then(({ data }) => {
        console.log(data)
        this.data = data.page
      })
    },
    getNode (data) {
      console.log('发送点击三级树', data)
      PubSub.publish('data', data)
    }
  }
}
</script>